/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author WangShuai
 */
public class RegexGroup {

    public static void main(String[] args) {
        //“()” --> group
        //1.capturing group
        //number: 0 is whole string; from left to right to number group
        // ((A)(B(C))) : there is four group

        //Back references: \n Whatever the n th capturing group matched string

        //2.non-capturing: ? start 
        //not store matched string into number group 
        //not have group number
        //can't use back ref

//        Pattern p = Pattern.compile("(?<!4)56(?=9)"); //find "56" ,ahead can't is 4 and behind must is 9
//        Matcher m = p.matcher("425690");
//        System.out.println(m.groupCount()); //0
//        while (m.find()) {
//            System.out.println(m.start() + "-" + m.end());
//            System.out.println(m.group()); //56   not capture the 56 ahead and behind string
//        }

        Pattern p2 = Pattern.compile("([a-z](?!100))+");
        Matcher m2 = p2.matcher("ajava100");
        System.out.println(m2.groupCount());
        while (m2.find()) {
            System.out.println(m2.start() + "-" + m2.end());
            System.out.println(m2.group());
        }
    }
}
